<script>
function scheduleLoad(subId){
	$.ajax({ 
        type: "GET", 
        url: "/it_center/Schedules/schedulesBySubIdGet/" + subId, 
        success: function(data){ 
       	 $("#schedules").html(data);
       	 $("#btnAdd").css("display", "inline");
       } 
	}); 
}

function scheduleDelete(subId){
	$.ajax({ 
        type: "GET", 
        url: "/it_center/Schedules/schedule_delete/" + subId + "/" + $("#hidListScheduleId").val(), 
        success: function(data){ 
       		$("#schedules").html(data);
       } 
   }); 
}

function scheduleEdit(subjectId, scheduleId){
	$("#mainForm").prop("action", "/it_center/Schedules/schedule_edit");
	$("#hidSubmitType").val("edit");
	$("#hidSubjectId").val(subjectId);
	$("#hidScheduleId").val(scheduleId);
	return $("#mainForm").submit();
}

function scheduleAdd(subjectId){
	$("#mainForm").prop("action", "/it_center/Schedules/schedule_add");
	$("#hidSubmitType").val("add");
	$("#hidSubjectId").val(subjectId);
	return $("#mainForm").submit();
}

function func_setListScheId(scheId, checkBoxId){
	var listId = $("#hidListScheduleId").val();
	
	if(document.getElementById(checkBoxId).checked ==true){
		if(listId == ''){
			listId = listId + scheId;
		}else{
			listId = listId + "," + scheId;
		}
	} else {
		if (listId.indexOf(",") > 0){
			var n=listId.split(",");
			var index = n.indexOf(scheId);

			if (index >= 0){
				n.splice(index, 1);
			}
			
		    listId = '';
			for (var i = 0; i < n.length; i++){
				
				if(listId == ''){
					listId = listId + n[i];
				}else{
					listId = listId + "," + n[i];
				} 
			}	
		} else {
			if (scheId.indexOf(listId) >= 0) {
				listId = '';
			}
		}
	}
	$("#hidListScheduleId").val(listId);
}

</script>

<form id="mainForm" method="post">	
	<input type="hidden" name=submitType id="hidSubmitType"/>
	<input type="hidden" name=subjectId id="hidSubjectId"/>
	<input type="hidden" name=scheduleId id="hidScheduleId"/>
	<input type="hidden" name="listScheId" id="hidListScheduleId"/>
</form>
	
<section id="content" class="cols-a">
	<section id="schedules" class="news-a">
		<?php if ($subid == NULL) {
			echo "<b> Chọn môn học để xem lịch học </b>";
		} else {
			echo $this->element('schedule_tab', array('schedules' => $schedules, 'subject' => $subject));
		}?>
	</section>
	<aside>
		<h3>Danh Sách Môn Học</h3>
		<nav>
			<ul>
				<?php foreach ($subjects as $subject):?>						
				<li><a onclick="scheduleLoad(<?php echo $subject['Subject']['sub_id'];?>)"><?php echo $subject['Subject']['sub_name'];?></a></li>
				<?php endforeach;?>
			</ul>
		</nav>
	</aside>
</section>